const powMod = (base, exponent, mod) => {
  base = BigInt(base);
  let result = BigInt(1);
  base = base % BigInt(mod);
  const NODBASE = 2n;

  while (exponent > 0) {
    if (exponent % NODBASE === 1n) {
      result = (result * base) % BigInt(mod);
    }
    base = (base * base) % BigInt(mod);
    exponent = exponent / NODBASE;
  }

  return Number(result);
};

let res = powMod(2, 100000n, 12345);
console.log(res);
console.info(100000n / 2n);
